# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_sql_operator import SparkSqlOperator

jms_dwd__dwd_yl_rt_wide_bill_detail = SparkSqlOperator(
    task_id='jms_dwd__dwd_yl_rt_wide_bill_detail',
    task_concurrency=1,
    pool_slots=10,
    master='yarn',
    name='jms_dwd__dwd_yl_rt_wide_bill_detail_{{ execution_date | cst_hour }}',
    sql='jms_dwd_realtime_full_link_hour/dwd/dwd_yl_rt_wide_bill_detail/execute.sql',
    driver_memory='8G',
    driver_cores=4,
    executor_cores=4,
    executor_memory='16G',
    num_executors=25,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    email=['yushuo@yl-scm.com','yl_bigdata@yl-scm.com'],
    conf={'spark.dynamicAllocation.enabled'                  : 'true',  # 动态资源开启
          'spark.shuffle.service.enabled'                    : 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors'             : 25,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 600,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead'                    : '2G',  # 堆外内存
          'spark.sql.shuffle.partitions'                     : 800,
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 1000,  # 每天生成 100个分区
              'hive.exec.max.dynamic.partitions.pernode': 1000,  # 每天生成 100 个分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)
